<?php
header("Content-Type: text/html; charset=utf-8"); 
require_once('sessionVal.php');

require("../config.inc.php");
require_once(COMM_PATH."BMS.php");
require_once (COMM_PATH . "upload.php");
require_once (COMM_PATH . "Trans.php");
require_once(COMM_PATH . "bookUtil.php");

$bms = new BMS();
$categoryList = $bms->getAllCategory();

if ($_SERVER['REQUEST_METHOD']=='POST'){
	
	$data['category'] = $_POST['F_CATEGORY'];
	$data['intro'] = $_POST['F_BOOK_RESERVE'];
	$txtPath = uploadBook($_FILES["zipFile"]["error"],$_FILES ["zipFile"]["tmp_name"], $_FILES ["zipFile"]["name"], $_FILES ["zipFile"]["size"]);
	$imgPath = uploadImage($_FILES["imageFile"]["error"],$_FILES ["imageFile"]["tmp_name"], $_FILES ["imageFile"]["name"], $_FILES ["imageFile"]["size"]);
	$data['path'] = $txtPath[2];
	$data['bookName'] =  $txtPath[1];//$_POST['F_BOOK_NAME'];
	$data['author'] =  $txtPath[0];//$_POST['F_AUTHOR'];
	$data['imagePath'] = $imgPath;
	$NOW_DATE = getFormatDate_underline();
	$data['createTime'] = $NOW_DATE;
	if($bms->insertData($bms->_BOOK, $data)){
		echo '<script type=\"text/javascript\">alert(\"保存成功！\");</script>';
	}else{
		echo '保存失败！';
		echo "<a href='booklist.php'>返回</a>";
		exit();
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
	<title>书籍管理</title>
	<link rel="stylesheet" href="../resources/css/admin/style.css" />
	<script src="../resources/js/jquerys/lib/jquery.js" type="text/javascript"></script>
	<script src="../resources/js/jquerys/lib/jquery.cookie.js" type="text/javascript"></script>
	<script type="text/javascript" src="../resources/js/util.js"></script>
	<script type="text/javascript">
		
	function check(){
		var Mainform = document.form1;
//		if(Mainform.F_BOOK_NAME.value==""){
//			alert("书籍名称不能为空！");
//			return false;
//		}
//		if(Mainform.F_BOOK_NAME.value.len()>200){
//			alert("书籍名称不能超过100个字！");
//			return false;
//		}
//		
//		if(Mainform.F_AUTHOR.value==""){
//			alert("作者不能为空！");
//			return false;
//		}
//		if(Mainform.F_AUTHOR.value.len()>100){
//			alert("作者不能超过50个字！");
//			return false;
//		}

		if(Mainform.F_CATEGORY.value==""){
			alert("类别不能为空！");
			return false;
		}
		
		return true;
		
	}
	</script>
	</head>
	<body>
	<div id="wrap">
		<div id="adminmenuback"></div>
		<div id="menu">
			<h3 class="menutop">控制台</h3>
			<?php require('menus.php');?>
		</div>
		<div id="main-content">
			<?php require('top.php');?>
          	  
          	<div id="wpcontent">
          		
          	    <h2>新增书籍</h2>
          	    <div id="mainform">
          	    	<form action="" name="form1"  method="post" enctype="multipart/form-data" onsubmit="javascript:return check();">
          	    		<table width="78%" border="1" align="center" cellspacing="0" id="table_1" class="table_1">
					 		<thead class="tb_side">
					 		<tr >
					 			<td colspan="2">&nbsp;</td>
					 		</tr>
					 		</thead>
					 		<tbody class="tb_body">
<!--					 		<tr>-->
<!--					 			<td width="25%" align="center">书籍名称<font color="red">*</font></td>-->
<!--					 			<td width="75%" colspan="3"><input type="text" name="F_BOOK_NAME"  style="width:300px;" /></td>-->
<!--					 		</tr>-->
					 		<tr>
<!--					 			<td align="center">作者<font color="red">*</font></td>-->
<!--					 			<td><input type="text" name="F_AUTHOR"  /></td>-->
					 			<td width="25%" align="center">类别<font color="red">*</font></td>
					 			<td width="75%" colspan="3">
					 				<select name="F_CATEGORY">
					 					<option value="">--请选择--</option>
					 					<?php
					 					if ($categoryList){
						 					 foreach ($categoryList as $key => $value) {
						 						echo "<option value=\"$value[BID]\">$value[cate_name]</option>";
						 					 }
					 					}
					 					
					 					?>
					 				</select>
					 			</td>
					 		</tr>
					 		<tr>
					 			<td align="center">书籍简介</td>
					 			<td colspan="3">
						 			<textarea rows="2" cols="50" name="F_BOOK_RESERVE"></textarea>
					 			</td>
					 		</tr>
					 		<tr>
					 			<td align="center">ZIP文档</td>
					 			<td colspan="3">
						 			<input  type="file" name="zipFile" />
					 			</td>
					 		</tr>
					 		<tr>
					 			<td align="center">封面图片</td>
					 			<td colspan="3">
						 			<input  type="file" name="imageFile" />
					 			</td>
					 		</tr>
					 		
					 		</tbody>
					 		<tfoot class="tb_side">
					 		<tr>
					 			<td colspan="4" align="center">
					 				<input type="submit" name="AddBook" value="保  存" class="button"/>&nbsp;&nbsp;&nbsp;&nbsp;
					 				<input type="reset" name="resetbtn" value="重  置" class="button"/>&nbsp;&nbsp;&nbsp;&nbsp;
					 				<input type="button" name="backbtn" value="返  回" class="button" onclick="javascript:window.location.href='booklist.php'"/>
					 			</td>
					 		</tr>
					 		</tfoot>
					 	</table>
          	    		
          	    	</form>
          	    </div>
          	</div>
          	  
		</div>
 	</div>
</body>
</html>

